package weaver.interfaces.jjy.duss.util;

import com.sap.mw.jco.JCO;
import weaver.interfaces.workflow.action.Action;
import java.io.IOException;


/**
 * @program: ecology-9-demo
 * @description: ${description}
 * @author: Dusongsong
 * @create: 2019-12-09
 */
public class FieldValueUtil {

    public String execute(String IV_TABNAME, String IV_FIELDNAME, String value) {
        SAPConnPool SAPConn = new SAPConnPool();
        JCO.Client myConnection = SAPConn.getConnection();
        JCO.Function bapi = SAPConn.excuteBapi("ZFM_GET_TEXT_TABLE");

        JCO.ParameterList input = bapi.getImportParameterList();//输入参数和结构处理
        //JCO.ParameterList inputtable= bapi.getTableParameterList();//输入表的处理

        //入参为字段
        input.setValue(IV_TABNAME, "IV_TABNAME");
        input.setValue(IV_FIELDNAME, "IV_FIELDNAME");

        //执行函数
        myConnection.execute(bapi);
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理

        //返回表
        JCO.Table t = Table00.getTable("ET_OUT");
        for (int i = 0; i < t.getNumRows(); i++) {
            t.setRow(i);
            if (value.equals(t.getValue("VALUE"))) {
                return (String) t.getValue("TEXT");
            }
        }

        return Action.SUCCESS;
    }

    public static void main(String[] args) throws IOException {
        FieldValueUtil hr000 = new FieldValueUtil();
        String str = hr000.execute("PS0001","ZHR_ZW","D06");
        System.out.println("TEXT:"+str);

    }
}
